package org.ezplatform.office.meeting.statistics.web.rest;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.ezplatform.core.common.WebUser;
import org.ezplatform.core.pagination.PropertyFilter;
import org.ezplatform.core.service.BaseService;
import org.ezplatform.core.web.controller.BaseController;
import org.ezplatform.core.web.util.WebUtils;
import org.ezplatform.core.web.view.OperationResult;
import org.ezplatform.office.meeting.info.entity.ApplyRecord;
import org.ezplatform.office.meeting.statistics.service.MeetingStatisticsService;
import org.ezplatform.util.ValidateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import net.logstash.logback.encoder.org.apache.commons.lang.StringUtils;

@RestController
@RequestMapping(value = "/api/w/meeting/statistics")
public class MeetingStatisticsWebApiController extends BaseController<ApplyRecord, String> {

	@Autowired
	private MeetingStatisticsService meetingStatisticsService;
	
	@Override
	protected BaseService<ApplyRecord, String> getEntityService() {
		return this.meetingStatisticsService;
	}
	
	/**
	 * 获取列表数据(分页)
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getAttendMeetingStatisticsPage", method = RequestMethod.GET)
	@RequiresPermissions({"meeting:statistics:03"})
    public Page<Map<String, Object>> getAttendMeetingStatisticsPage(HttpServletRequest request) {
		WebUser user = WebUtils.getCurrentUser();
		String corpId = user.getCorpId();
		Pageable pageable = PropertyFilter.buildPageableFromHttpRequest(request);
		String name = ValidateUtils.filter(request.getParameter("userName"));
		String orgId = ValidateUtils.filter(request.getParameter("attendOrgId"));
		String startTime = ValidateUtils.filter(request.getParameter("startTime"));
		String endTime = ValidateUtils.filter(request.getParameter("endTime"));
		return meetingStatisticsService.getAttendMeetingStatisticsPage(pageable, corpId, name, orgId, startTime, endTime);
    }
	
	/**
	 * 获取列表数据(分页)
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getMeetingStatisticsPage", method = RequestMethod.GET)
	@RequiresPermissions({"meeting:statistics:03"})
    public Page<Map<String, Object>> getMeetingStatisticsPage(HttpServletRequest request) {
		WebUser user = WebUtils.getCurrentUser();
		String corpId = user.getCorpId();
		Pageable pageable = PropertyFilter.buildPageableFromHttpRequest(request);
		String meetingType = ValidateUtils.filter(request.getParameter("meetingType"));
		String meetingInitiator = ValidateUtils.filter(request.getParameter("meetingInitiator"));
		String startTime = ValidateUtils.filter(request.getParameter("startTime"));
		String endTime = ValidateUtils.filter(request.getParameter("endTime"));
		return meetingStatisticsService.getMeetingStatisticsPage(pageable, corpId, meetingType, meetingInitiator, startTime, endTime);
    }
	
	/**
	 * 获取列表数据(分页)
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getTaskStatisticsPage", method = RequestMethod.GET)
	@RequiresPermissions({"meeting:statistics:03"})
    public Page<Map<String, Object>> getTaskStatisticsPage(HttpServletRequest request) {
		WebUser user = WebUtils.getCurrentUser();
		String corpId = user.getCorpId();
		Pageable pageable = PropertyFilter.buildPageableFromHttpRequest(request);
		String name = ValidateUtils.filter(request.getParameter("userName"));
		String orgId = ValidateUtils.filter(request.getParameter("taskOrgId"));
		String startTime = ValidateUtils.filter(request.getParameter("startTime"));
		String endTime = ValidateUtils.filter(request.getParameter("endTime"));
		return meetingStatisticsService.getTaskStatisticsPage(pageable, corpId, name, orgId, startTime, endTime);
    }
	
	/**
     * 查询部门树数据
     * 
     * @return
     */
    @RequestMapping(value = "/getOrgTreeData", method = RequestMethod.GET)
    public OperationResult getOrgTreeData(HttpServletRequest request) {
        WebUser user = WebUtils.getCurrentUser();
        String corpId = user.getCorpId();
        String jeson = this.meetingStatisticsService.getManageOrgTreeData(user.getUserId(),user.getUserName(),request,corpId,TOKEN);
        return OperationResult.buildSuccessResult("", jeson);
    }
}
